﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utility1;

namespace eDream
{
    public partial class index : System.Web.UI.Page
    {
        public string pathUrl = "";
        public string cssClass = "margin-top:-37px";
        protected void Page_Load(object sender, EventArgs e)
        {
           
            UserDB user_obj = (UserDB)Session[Global.SESS_USER];
            pathUrl = WebUtils.pathUrl();
            string name = "";
            string id = "";
            name = Utils.GetParameter("page", "home");
            if (!IsPostBack)
            {
                if (name == "thoat")
                {
                    Session.RemoveAll();
                    btnDangky.Visible = true;
                    btnDangnhap.Visible = true;
                    hdfdangnhap.Value = null;
                    hdflinkdangky.Value = null;
                }
                else
                    try
                    {
                        if (user_obj != null)
                        {
                            btnDangky.Visible = false;
                            btnDangnhap.Visible = false;
                            hdflinkdangky.Value = "<div style='float:left; margin-top:5px;color:#3b3b3b'>Xin chào: </div>";
                            if (user_obj.kichhoat == true)
                                hdfdangnhap.Value = "<div style='float:left; margin-top:5px;color:#3b3b3b'><a href='/Canhan.aspx'>" + user_obj.UserName + "</a></div><div style='clear: both;height: 0;overflow: hidden;'></div><div><a href='http://msmart.vn/thoat.html'>Thoát</a></div>";
                            else
                                hdfdangnhap.Value = "<div style='float:left; margin-top:5px;color:#3b3b3b'>" + user_obj.UserName + " </div><div style='clear: both;height: 0;overflow: hidden;'></div><div><a href='http://msmart.vn/thoat.html'></a>Thoát</div>";
                        }
                    }
                    catch (Exception) { }
            }
            try
            {

               
               
                // if(RouteData.Values["id"]!=null)
                //    id= RouteData.Values["id"].ToString();
                /*
                if (RouteData.Values["page"] != null)
                    name = RouteData.Values["page"].ToString();
                else if (RouteData.Values["home"] != null)
                    name = RouteData.Values["home"].ToString();
                else if (RouteData.Values["pages"] != null)
                    name = RouteData.Values["pages"].ToString();
                else
                    name = "Trang-chu";
                if (RouteData.Values["proname"] != null)
                    id = RouteData.Values["proname"].ToString();
                if (RouteData.Values["cateId"] != null)
                    id = RouteData.Values["cateId"].ToString();
                */
               
               
                getPageName(name);

            }
            catch (Exception) { }
        }

        private void getPageName(string pageName)
        {
            try
            {

                switch (pageName)
                {
                    case "Trang-chu":
                        pageName = SiteNavigation.contronl_home;
                        cssClass = "";
                        divMenu.Visible = false;
                        if(!IsPostBack)
                        poupThongbao.ShowOnPageLoad = true;
                        break;
                    case "San-pham":
                        pageName = SiteNavigation.contronl_detail;
                        break;
                    case "San-pham-moi":
                        pageName = SiteNavigation.contronl_sanphammoi;
                        break;
                    case "Dia-diem-lien-ket":
                        pageName = SiteNavigation.contronl_lienket;
                        break;
                    case "Gioi-thieu":
                        pageName = SiteNavigation.contronl_gioithieu;
                        break;
                    case "Dang-ky":
                        pageName = SiteNavigation.contronl_register;
                        break;
                    case "Ho-tro":
                        pageName = SiteNavigation.contronl_help;
                        break;
                    case "Tim-kiem":
                        pageName = SiteNavigation.contronl_Tim_kiem;
                        break;
                    case "Gio-hang":
                        pageName = SiteNavigation.contronl_giohang;
                        break;
                    case "Don-hang":
                        pageName = SiteNavigation.contronl_Donhang;
                        break;
                    case "Thank":
                        pageName = SiteNavigation.contronl_Thank;
                        break;
                //chuyen de
                    case "Goc-tu-van":
                        pageName = SiteNavigation.contronl_Goc_tu_van;
                        break;
                    case "Thong-tin-tu-van":
                        pageName = SiteNavigation.contronl_thong_tin_tu_van;
                        break;
                    case "Suc-khoe-va-doi-song":
                        pageName = SiteNavigation.contronl_Dinh_duong;
                        break;
                    case "Thong-tin-suc-khoe-va-doi-song":
                        pageName = SiteNavigation.contronl_thong_tin_suc_khoe;
                        break;
                    case "Tuyen-dung":
                        pageName = SiteNavigation.contronl_tuyen_dung;
                        break;
                    case "Quen-mat-khau":
                        pageName = SiteNavigation.contronl_Quenmatkhau;
                        break;
                    default:
                        pageName = SiteNavigation.contronl_home;
                        cssClass = "";
                        divMenu.Visible = false;
                        break;
                }

                UserControl contentView = (UserControl)Page.LoadControl(pageName);
                phdContent.Controls.Add(contentView);
            }
            catch (Exception ex)
            {
                // Response.Redirect(SiteNavigation.LoginPageDMS);
            }
        }



        protected void btOK_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                dx.Connection.Open();
                var list = from k in dx.UserDBs
                           where k.UserName == tbLogin.Text.Trim() && k.Password == Global.ToEncoding(tbPassword.Text.Trim()) && k.visible == true
                           select k;

                foreach (UserDB u in list)
                {
                    Session[Global.SESS_USER] = u;
                }
                Session.Timeout = 120;
                string link = pathUrl + "/Trang-chu.html";
                if (Session[Global.SESS_USER] != null)
                    Response.Redirect(link);
                else
                {
                    lbe.ForeColor = Color.Red; lbe.Text = "Tên đang nhập hoặc mật khẩu không đúng";
                }
            }
            catch (Exception) { lbe.ForeColor = Color.Red; lbe.Text = "Tên đang nhập hoặc mật khẩu không đúng"; }
            finally { dx.Connection.Close(); }
        }

        protected void ASPxButton11_Click(object sender, EventArgs e)
        {
            String link = pathUrl + "/Dang-ky.html";
            Response.Redirect(link);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            String link = "/Tim-kiem/" + txtSearch.Text.Trim().Replace("+", "").Replace("*", "").Replace("/", "").Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "") + "/Ket-qua.html";
            Response.Redirect(link);
        }

        protected void btnSent_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                dx.Connection.Open();
                Feeback_tb fb = new Feeback_tb();
                fb.diachi = txtDiachi.Text.Trim();
                fb.dienthoai = txtDienthoai.Text.Trim();
                fb.email = txtEmail.Text.Trim();
                fb.hovaten = txtHovaten.Text.Trim();
                fb.note = txtNode.Text;
                if (ASPxCheckBox1.Checked == true)
                    fb.t1 = 1;
                else if (ASPxCheckBox2.Checked == true)
                    fb.t1 = 2;
                else if (ASPxCheckBox3.Checked == true)
                    fb.t1 = 3;
                else if (ASPxCheckBox4.Checked == true)
                    fb.t1 = 4;

                if (ASPxCheckBox5.Checked == true)
                    fb.t2 = 1;
                else if (ASPxCheckBox6.Checked == true)
                    fb.t2 = 2;
                else if (ASPxCheckBox7.Checked == true)
                    fb.t2 = 3;
                else if (ASPxCheckBox8.Checked == true)
                    fb.t2 = 4;

                if (ASPxCheckBox9.Checked == true)
                    fb.t3 = 1;
                else if (ASPxCheckBox10.Checked == true)
                    fb.t3 = 2;
                else if (ASPxCheckBox11.Checked == true)
                    fb.t3 = 3;
                else if (ASPxCheckBox12.Checked == true)
                    fb.t3 = 4;

                if (ASPxCheckBox13.Checked == true)
                    fb.t4 = 1;
                else if (ASPxCheckBox14.Checked == true)
                    fb.t4 = 2;
                else if (ASPxCheckBox15.Checked == true)
                    fb.t4 = 3;
                else if (ASPxCheckBox16.Checked == true)
                    fb.t4 = 4;

                if (ASPxCheckBox17.Checked == true)
                    fb.t5 = 1;
                else if (ASPxCheckBox18.Checked == true)
                    fb.t5 = 2;
                else if (ASPxCheckBox19.Checked == true)
                    fb.t5 = 3;
                else if (ASPxCheckBox20.Checked == true)
                    fb.t5 = 4;

                if (ASPxCheckBox21.Checked == true)
                    fb.t6 = 1;
                else if (ASPxCheckBox22.Checked == true)
                    fb.t6 = 2;
                else if (ASPxCheckBox23.Checked == true)
                    fb.t6 = 3;
                else if (ASPxCheckBox24.Checked == true)
                    fb.t6 = 4;

                if (ASPxCheckBox25.Checked == true)
                    fb.t7 = 1;
                else if (ASPxCheckBox26.Checked == true)
                    fb.t7 = 2;
                else if (ASPxCheckBox27.Checked == true)
                    fb.t7 = 3;
                else if (ASPxCheckBox28.Checked == true)
                    fb.t7 = 4;

                if (ASPxCheckBox29.Checked == true)
                    fb.t8 = 1;
                else if (ASPxCheckBox30.Checked == true)
                    fb.t8 = 2;
                else if (ASPxCheckBox31.Checked == true)
                    fb.t8 = 3;
                else if (ASPxCheckBox32.Checked == true)
                    fb.t8 = 4;

                if (ASPxCheckBox33.Checked == true)
                    fb.t9 = 1;
                else if (ASPxCheckBox34.Checked == true)
                    fb.t9 = 2;
                else if (ASPxCheckBox35.Checked == true)
                    fb.t9 = 3;
                else if (ASPxCheckBox36.Checked == true)
                    fb.t9 = 4;

                if (ASPxCheckBox37.Checked == true)
                    fb.gioithieu = true;
                else
                    fb.gioithieu = false;

                fb.datePost = DateTime.Now;
                fb.flag = true;

                dx.Feeback_tbs.InsertOnSubmit(fb);
                dx.SubmitChanges();

                ASPxCheckBox1.Checked = false;
                ASPxCheckBox2.Checked = false;
                ASPxCheckBox3.Checked = false;
                ASPxCheckBox4.Checked = false;
                ASPxCheckBox5.Checked = false;
                ASPxCheckBox6.Checked = false;
                ASPxCheckBox7.Checked = false;
                ASPxCheckBox8.Checked = false;
                ASPxCheckBox9.Checked = false;
                ASPxCheckBox10.Checked = false;
                ASPxCheckBox11.Checked = false;
                ASPxCheckBox12.Checked = false;
                ASPxCheckBox13.Checked = false;
                ASPxCheckBox14.Checked = false;
                ASPxCheckBox15.Checked = false;
                ASPxCheckBox16.Checked = false;
                ASPxCheckBox17.Checked = false;
                ASPxCheckBox18.Checked = false;
                ASPxCheckBox19.Checked = false;
                ASPxCheckBox20.Checked = false;
                ASPxCheckBox21.Checked = false;
                ASPxCheckBox22.Checked = false;
                ASPxCheckBox23.Checked = false;
                ASPxCheckBox24.Checked = false;
                ASPxCheckBox25.Checked = false;
                ASPxCheckBox26.Checked = false;
                ASPxCheckBox27.Checked = false;
                ASPxCheckBox28.Checked = false;
                ASPxCheckBox29.Checked = false;

                ASPxCheckBox30.Checked = false;
                ASPxCheckBox31.Checked = false;
                ASPxCheckBox32.Checked = false;
                ASPxCheckBox33.Checked = false;
                ASPxCheckBox34.Checked = false;
                ASPxCheckBox35.Checked = false;
                ASPxCheckBox36.Checked = false;

                ASPxCheckBox37.Checked = false;
                ASPxCheckBox38.Checked = false;

                txtDiachi.Text = "";
                txtDienthoai.Text = "";
                txtEmail.Text = "";
                txtNode.Text = "";

                Panel2.Visible = false;
                Panel3.Visible = true;
            }
            catch (Exception) { }
            finally { dx.Connection.Close(); }

            
        }

        protected void btnLienhe_Click(object sender, EventArgs e)
        {
            GoogleMail g = new GoogleMail();
            string noidung = "Khách hàng: " + txtHoten1.Text.Trim() +"<br/> Email: " + txtEmail1.Text.Trim() +"<br/> Điện thoại: " + txtDT1.Text +"<br/> Vào lúc: " + DateTime.Now.ToLongTimeString() + " ngày " +  DateTime.Now.ToLongDateString() + " đã gửi liên hệ với nội dung sau: <br/>";
            string note = "<br/> <br/><i>Node: Đây là thông tin được gửi từ hệ thống tiếp nhận thông tin Liên hệ của khách hàng tới <b>Ban Lãnh Đạo Công Ty Cổ Phần Cung Cấp Giải Pháp Truyền Thông Việt Nam</b> vui lòng không reply lại Email này.</i>";

            g.Send("thinhvuongphatdat@gmail.com", "msmart.jsc@gmail.com", null, txtTieude1.Text.Trim(), " <br/> " + noidung + "<p style=" + '"' + "font-weight:bold" + '"' + "> " + '"' + txtNoidung1.Text.Trim() + '"' + "</p> " + note, null);

            Panel4.Visible = false;
            Panel5.Visible = true;
        }
    }
}